<?php 
require_once 'library/CGManager.php';
require_once 'library/ConfigManager.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>CodeGen V. <?php echo CGManager::$CG_VERSION ?></title>

<!--CSS-->
<link rel="stylesheet" type="text/css" href="assets/css/CodeGen.css" media="all"/>
<link rel="stylesheet" type="text/css" href="assets/js/jquery.jcarousel.css" media="all"/>
<link rel="stylesheet" type="text/css" href="assets/js/tango/skin.css" media="all"/>
<link rel="stylesheet" type="text/css" href="assets/js/smoothness/ui.all.css" media="all"/>

<!--JS-->
<script src="assets/js/jquery.js" type="text/javascript"></script>
<script src="assets/js/jquery-ui.js" type="text/javascript"></script>
<script src="assets/js/jquery.json.js" type="text/javascript"></script>
<script src="assets/js/jquery.jcarousel.js" type="text/javascript"></script>

<script type="text/javascript">
	

$(function()
{ 
	var baseURL = "http://" + window.location.hostname + "/CodeGen";	
	var service = "library/FlexService.php";
	var cg_host;//Host
	var cg_user;//Username
	var cg_pass;//Password
	var cg_database;//Database
	var cg_app;//Application
	var cg_namespace;//Namespace
	var cg_endpoint;//Endpoint
	var cg_framework;//Framework
	var cg_copywrite;//Copywrite
	var cg_config;//Config
	var cg_schema;//Schema
	var resultData;
	
	$("#cgCarousel").jcarousel(
	{  
		start: 1,
		scroll: 1,
		animation: 'slow',
		wrap: 'both'
	});

	// Dialog			
				$('#dialog').dialog({
					autoOpen: false,
					width: 600,
					height: 550,
					buttons: {
						"Ok": function() { 
							$(this).dialog("close"); 
						}
					}
				});
				
				// Dialog Link
				$('#dialoglink').click(function(){
					$('#dialog').dialog('open');
					return false;
				});
	
	
	$("#txt_pass").blur(function()
	{
		//m=getDatabases&h=localhost&u=root&p=fred
		$.get( service, { 
			m: 'getDatabases',
			h: $("#txt_host").val(),
			u: $("#txt_user").val(),
			p: $("#txt_pass").val(),
		}, function( result ){
			var options = '';
			var dbArray = [];
			var dbArray = $.evalJSON( result );
			
			for ( i = 0; i < dbArray.length; i++ )
			{
				options += '<option>' + dbArray[ i ][ 'label' ] + '</option>';
			}
			$("select#txt_database").html( options );
		} );
	});
	

	
 
	
/* ======================================================================
 *  						Config Form
 * ====================================================================== */
	$("#btn_generateConfig").click(function()
	{	
		//Step 1
		cg_host = $("#txt_host").val();
		cg_user = $("#txt_user").val();
		cg_pass = $("#txt_pass").val();
		cg_database = $("#txt_database").val();
		
		//Step 2
		cg_app = $("#txt_application").val();
		cg_namespace = $("#txt_namespace").val();
		cg_endpoint = $("#txt_endpoint").val();
		cg_framework = $("#txt_framework").val();
		cg_copywrite = $("#txt_copywrite").val();
		
		//Send the call
		$.get( service,
		{ 
			m: 'generateConfig', //Mode
			h: cg_host, 
			u: cg_user, 
			p: cg_pass, 
			d: cg_database, 
			a: cg_app, 
			n: cg_namespace, 
			e: cg_endpoint, 
			f: cg_framework, 
			c: cg_copywrite
			}, function( result )
			{
				result = $.trim( result ).replace(  /[\\]*[\\"]/g, '' );
					
				$("#message").html( "Config.xml Location: " + result ).fadeIn("slow", function()
				{
				//Set the config location to the result
				cg_config = result;
				
				$("#configLocation").html( result );
				$("#txt_configLocation").val( result );	
			});
		});
	});
	
	
	
/* ======================================================================
 *  						Schema Form
 * ====================================================================== */
	$("#btn_generateSchema").click( function() 
	{
		$.get( service, 
		{ 
			m: "generateSchema", 
			c: cg_config, 
			d: cg_database 
			}, function( result )
			{
				result = $.trim( result ).replace(  /[\\]*[\\"]/g, '' );
			
				$("#message").html( "Schema Location: " + result ).fadeIn("slow", function()
				{	
					//Set the schema location to the result
					cg_schema = result;
					$("#schemaLocation").html( result );
					$("#txt_schemaLocation").val( result );
					
				});
		});
	});
	
/* ======================================================================
 *  						Application Form
 * ====================================================================== */
	$("#btn_generateApp").click( function() 
	{
		cg_config = $("#txt_configLocation").val();
		cg_database = $("#txt_database").val();
		$.get( service, 
		{ 
			m: "generateApplication",  
			d: cg_database,
			s: cg_schema
			}, function( result ) 
			{
				result = $.trim( result ).replace(  /^(..)/gi, '' );	
				
				$("#iframe_preview").attr( "src", baseURL + result );
				$('#dialog').dialog( 'open' );
				$("#pre_dump").html( result ).toggle("slow" );
	
			//alert( result);
		});
	});
	
	function getDemoURL()
	{
		$.get( service, 
		{ 
			m: 'getHTMLDemo' 
		},function( result ){
			
			//result = $.trim( result ).replace(  /[\\]*[\\"]/g, '' );
			$("#iframe_preview").attr( "src", result );
		});
	}
		
});
</script>
</head>
<body>
	
	
	
<div id="container">
<div id="header">
<h1><a href="http://jonniespratley.com">CodeGen: v. <?php echo CGManager::$CG_VERSION ?> the rapid php &amp; flex generator</a></h1>
</div><!--ends #header-->

<div id="content">
<div id="message" class="message" style="display:none;"></div><!--ends #message-->



<div id="dialog">
	<iframe id="iframe_preview" width="100%"  height="100%">
	</iframe><!--ends #iframe_preview-->    
</div>


 
<div class="slider">
	<ul id="cgCarousel" class="jcarousel-skin-tango">
